/**
* @program: Go
*
* @description:发送邮件
*
* @author: Mr.chen
*
* @create: 2020-08-20 10:37
**/
package logger

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"runtime/debug"
	"ydd-im/config"
	"ydd-im/util/go-util/mail"
	"ydd-im/util/go-util/time"
	"strings"
)
type sendToemail struct {}
func (s *sendToemail) sendemail(c *gin.Context,err interface{}) {
	DebugStack := ""
	for _, v := range strings.Split(string(debug.Stack()), "\n") {
		DebugStack += v + "<br>"
	}

	subject := fmt.Sprintf("【重要错误】%s 项目出错了！", config.AppName)

	body := strings.ReplaceAll(MailTemplate, "{ErrorMsg}", fmt.Sprintf("%s", err))
	body  = strings.ReplaceAll(body, "{RequestTime}", time.GetCurrentDate())
	body  = strings.ReplaceAll(body, "{RequestURL}", c.Request.Method + "  " + c.Request.Host + c.Request.RequestURI)
	body  = strings.ReplaceAll(body, "{RequestUA}", c.Request.UserAgent())
	body  = strings.ReplaceAll(body, "{RequestIP}", c.ClientIP())
	body  = strings.ReplaceAll(body, "{DebugStack}", DebugStack)

	options := &mail.Options{
		MailHost : config.SystemEmailHost,
		MailPort : config.SystemEmailPort,
		MailUser : config.SystemEmailUser,
		MailPass : config.SystemEmailPass,
		MailTo   : config.ErrorNotifyUser,
		Subject  : subject,
		Body     : body,
	}
	_ = mail.Send(options)

	//util.ResponseJsonFail(c,util.Response{
	//	Code:500,
	//	Message:"系统异常，请联系管理员！",
	//})


}
